package Ioperate;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class AddBook implements Ioperate{
    public void work(BookList bookList){
        Scanner scanner = new Scanner(System.in);
        int count = bookList.getSize();
        int i = 0;

        System.out.println("请输入书名：");
        String name = scanner.nextLine();
        System.out.println("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入价格：");
        int price = scanner.nextInt();
        String s = scanner.nextLine();
        System.out.println("请输入书的类型：");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);
        for(i=0;i<count;i++){
            if(bookList.getBooks(i).equals(name)){
                System.out.println("此书已存在！");
                System.out.println();
                return ;
            }
        }

        System.out.println("加入成功！");
        System.out.println();
        bookList.setBooks(count,book);
        bookList.setSize(count+1);
    }
}
